// pages/fmList/fmList.js
const app = getApp();
import {$await} from '../../utils/util';
import {actListAPI} from '../../api/public/index'
const CONFIG = require('../../config');
const util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl : "https://images.weserv.nl/?url="+CONFIG.imgUrlImg,
	list: [],
    listes: [
		{
			"time":"3月29日-4月3日",
			"src":"http://mmbiz.qpic.cn/mmbiz_jpg/5tcBNW4boWAbG7qXvdDdtvoYVmyg7Fyiags0MjiaCyt4KQskiaCgGDmIggBd7UQc8Ps2JlicEib7SbKaIudIgayPNHg/0",
			"type":1
		},
		{
			"time":"3月29日-4月3日",
			"src":"http://mmbiz.qpic.cn/mmbiz_jpg/5tcBNW4boWAbG7qXvdDdtvoYVmyg7Fyiags0MjiaCyt4KQskiaCgGDmIggBd7UQc8Ps2JlicEib7SbKaIudIgayPNHg/0",
			"type":0
		},
	],
	
    page:1
  },

  goLocIndex(e){
    console.log(e.currentTarget.dataset)
    let { number } = e.currentTarget.dataset
    wx.navigateTo({
      url: '/pages/localindex/localindex?channelId='+number,
    })
    getApp().globalData.tabBarType = 'local';
  },
  async getList() {
	let data={
		page:this.data.page,
		pageSize:10,  
	}
    let [err,res] = await $await(actListAPI.actList(data))
    if(res){
      let time = Math.round(new Date() / 1000)
	  for(let i in res){
		  res[i].start_time1=util.formatTime(res[i].start_time,'M月D日');
		  res[i].end_time1=util.formatTime(res[i].end_time,'M月D日');
		  if(time>res[i].end_time){
			res[i].status=2 
		  }else if(time>res[i].start_time && time<res[i].end_time){
			res[i].status=1   
		  }else{
			res[i].status=0    
		  }
	  }
	  console.log(res)
      this.data.list.push(...res)
      this.setData({
        list: this.data.list
      })
    }
  },
  toDetail(e){
	let index = e.currentTarget.dataset.index;
	let menu = this.data.list;
	let url = menu[index].url;
	wx.navigateTo({
		url: '/pages/webview/webview?webURL=' + url,
	})
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.data.page += 1
    this.getList()
    console.log(this.data.page)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})